home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / telecomm / sticpsrc.lzh / SOURCE.ARC / KISS.C < prev    next >
C/C++ Source or Header  |  1990-01-07  |  2KB  |  93 lines

  1. #include "global.h"
  2. #include "mbuf.h"
  3. #include "iface.h"
  4. #include "kiss.h"
  5. #include "trace.h"
  6.  
  7. /* Send raw data packet on KISS TNC */
  8. kiss_raw(interface,data)
  9. struct interface *interface;
  10. struct mbuf *data;
  11. {
  12.     register struct mbuf *bp;
  13.  
  14.     dump(interface,IF_TRACE_OUT,TRACE_AX25,data);
  15.  
  16.     /* Put type field for KISS TNC on front */
  17.     if((bp = pushdown(data,1)) == NULLBUF){
  18.         free_p(data);
  19.         return;
  20.     }
  21.     if(interface->kisschan == 0) {
  22.         bp->data[0] = KISS_DATA;
  23.     } else {
  24.         bp->data[0] = (interface->kisschan << 4) | KISS_DATA;
  25.         interface = interface->kiss->iface[0];
  26.     }
  27.  
  28.     (*interface->slipraw)(interface,bp);
  29. }
  30.  
  31. /* Process incoming KISS TNC frame */
  32. void
  33. kiss_recv(interface,bp)
  34. struct interface *interface;
  35. struct mbuf *bp;
  36. {
  37.     char kisstype;
  38.  
  39.     kisstype = pullchar(&bp);
  40.  
  41.     if(interface->kiss != NULLKISS) {
  42.         /* multi-channel KISS, get channel# and determine iface */
  43.         if((interface = interface->kiss->iface[(uchar(kisstype) >> 4)]) == NULLIF){
  44.             free_p(bp);        /* unknown channel */
  45.             return;
  46.         }
  47.     }
  48.  
  49.     switch(kisstype & 0x0f){
  50.     case KISS_DATA:
  51.         dump(interface,IF_TRACE_IN,TRACE_AX25,bp);
  52.         ax_recv(interface,bp);
  53.         break;
  54.     default:
  55.         free_p(bp);
  56.         break;
  57.     }
  58. }
  59. /* Perform device control on KISS TNC by sending control messages */
  60. kiss_ioctl(interface,argc,argv)
  61. struct interface *interface;
  62. int argc;
  63. char *argv[];
  64. {
  65.     struct mbuf *hbp;
  66.     int i;
  67.     char *cp;
  68.  
  69.     if(argc < 1){
  70.         printf("Data field missing\r\n");
  71.         return 1;
  72.     }
  73.     /* Allocate space for arg bytes */
  74.     if((hbp = alloc_mbuf((int16)argc)) == NULLBUF){
  75.         free_p(hbp);
  76.         return 0;
  77.     }
  78.     hbp->cnt = argc;
  79.     hbp->next = NULLBUF;
  80.     for(i=0,cp = hbp->data;i < argc;)
  81.         *cp++ = atoi(argv[i++]);
  82.  
  83.     /* on extended KISS channels, replace 1st nibble with number */
  84.     if(interface->kisschan != 0){
  85.         interface = interface->kiss->iface[0];
  86.         hbp->data[0] = (interface->kisschan << 4) | (hbp->data[0] & 0x0f);
  87.     }
  88.  
  89.     (*interface->slipraw)(interface,hbp);    /* Even more "raw" than kiss_raw */
  90.     return 0;
  91. }
  92.  
  93.